package org.domeos.framework.api.service.global.impl;

import org.domeos.basemodel.HttpResponseTemp;
import org.domeos.basemodel.ResultStat;
import org.domeos.framework.api.biz.global.GlobalBiz;
import org.domeos.framework.api.model.global.GlobalInfo;
import org.domeos.framework.api.model.global.Percent;
import org.domeos.framework.api.service.global.PercentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class PercentServiceImpl implements PercentService {
	@Autowired
	GlobalBiz globalbiz;
	
	public HttpResponseTemp<?> getPercent(){
		Percent percent = new Percent();
		percent.setCpupercent(Double.toString(globalbiz.getCpuPercent()));
		percent.setMemorypercent(Double.toString(globalbiz.getMemoryPercent()));
		return ResultStat.OK.wrap(percent);
	}
	

	public HttpResponseTemp<?> updatepercent(String cpupercent,String memorypercent){
		try {
			Double.valueOf(cpupercent).doubleValue();
			Double.valueOf(memorypercent).doubleValue();
		}catch (Exception e) {
			return ResultStat.PARAM_ERROR.wrap("参数格式错误");
		}
		System.out.println(cpupercent);
		System.out.println(memorypercent);
		globalbiz.updateCpuPercent(cpupercent);
		globalbiz.updateMemoryPercent(memorypercent);
		return ResultStat.OK.wrap("ok");
	}
}
